package Config::System::t::Examples;

use strict;
use warnings;
use Test::More;
use Cwd;

use base 'Test::Class';

sub run_eg($;$) {
    my ($script, $args) = @_;
    $args = '' unless defined $args;
    my $cwd = getcwd;
    chdir("../eg");
    my $result = `$^X $script.pl $args`;
    chdir($cwd);
    chomp($result);
    return $result;
}

sub examples: Test(6) {
    for (
        [simple                => "Verbose is: [1]"                 ],
        [set_property          => "Verbose is: [0]"                 ],
        [choose_config_file    => "Verbose is: [0]"                 ],
        [run_isolated          => "Verbose is: [0]\nVerbose is: [1]"],
        [expression_dependency => "My_Exec is: [/foo/qux.exe]"      ],
        [link                  => "Verbose is: [1], Color is: [red]"],
    ) {
        my ($script, $expected) = @$_;
        is run_eg($script), $expected, "testing $script";
    }
}

sub getopt: Test {
    is
        run_eg(cli_override => '-some_option qux -set Foo::Verbose=0'),
        "some_option is: [qux]\nVerbose is: [0]";
}

1;
